#include "pistache/asyncrt_utils.h"

namespace
{
struct to_lower_ch_impl
{
	char operator()(char c) const _NOEXCEPT
	{
		if (c >= 'A' && c <= 'Z') return static_cast<char>(c - 'A' + 'a');
		return c;
	}

	wchar_t operator()(wchar_t c) const _NOEXCEPT
	{
		if (c >= L'A' && c <= L'Z') return static_cast<wchar_t>(c - L'A' + L'a');
		return c;
	}
};

_CONSTEXPR to_lower_ch_impl to_lower_ch {};

struct eq_lower_ch_impl
{
template<class CharT>
inline CharT operator()(const CharT left, const CharT right) const _NOEXCEPT
{
	return to_lower_ch(left) == to_lower_ch(right);
}
};

_CONSTEXPR eq_lower_ch_impl eq_lower_ch {};

struct lt_lower_ch_impl
{
template<class CharT>
inline CharT operator()(const CharT left, const CharT right) const _NOEXCEPT
{
	return to_lower_ch(left) < to_lower_ch(right);
}
};

_CONSTEXPR lt_lower_ch_impl lt_lower_ch {};
} // namespace

namespace Utility
{
namespace Details
{

void inplace_tolower(std::string &target) _NOEXCEPT
{
	for (auto &ch: target)
	{
		ch = to_lower_ch(ch);
	}
}

}
}